<script>
var i = 1;
function addSocial()
{
    $.ajax({
        url: '<?php echo Yii::app()->createUrl("/Events/request/placeAddSocial");?>',
        type: 'post',
        data: {i: i},
        success: function (data)
        {
             i = i+ 1;
            $(data).appendTo('#listSocial');
        }
    });
}

function delPlaceImage(id)
{
	var r = confirm("Bạn có chắc chắn muốn xóa!");
	if ( r === true )
	{
		$.ajax({
			url: '<?php echo Yii::app()->createUrl("/Events/request/placeDelPlaceImage");?>',
			type: 'post',
			data: {id: id},
			success: function (data){
				if (data == "success")
					$('#place-image-'+id).remove();
				else
					alert("ERROR ! Bạn hãy thực hiện lại!");
			}
		});
	}
}
</script>
<!-- BEGIN NEWS FORM -->
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'places-form',
	'enableClientValidation'=>false,
	'clientOptions'=>array(
		'validateOnSubmit'=>true,
	),
	'htmlOptions'=>array(
		'class'=>'horizontal-form',
		'enctype'=>'multipart/form-data'
	),
)); ?>
<div class="form-body">
    <div class="row">
        <div class="col-md-3" style="overflow: hidden;">
            <!-- IMAGE PLACE -->
            <div class="fileupload fileupload-new <?php echo ($model->getError('image') ? 'has-error' : ''); ?>" data-provides="fileupload">
				<div class="fileupload-new thumbnail" style="width: 240px; height: 150px;">
                <?php if ($model->isNewRecord) : ?>
					<img src="<?php echo Yii::app()->theme->baseUrl; ?>/img/no_image.gif" alt="" />
                <?php else : ?>
                	<img src="<?php echo $this->getImageUrl() . 'places/' . date('Ymd', strtotime($model->createddate)) . '/' . $model->image; ?>" alt="" />
                <?php endif; ?>
				</div>
				<div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 240px; max-height: 150px; line-height: 20px;"></div>
				<div>
					<span class="btn default btn-file">
						<span class="fileupload-new"><i class="icon-paper-clip"></i> Select image</span>
						<span class="fileupload-exists"><i class="icon-undo"></i> Change</span>
						<?php echo $form->fileField($model, 'image', array('class'=>'default')); ?>
					</span>
					<a href="#" class="btn red fileupload-exists" data-dismiss="fileupload"><i class="icon-trash"></i> Remove</a>
				</div>
                <?php echo $form->error($model, 'image', array('class'=>'help-block')); ?>
			</div>
            <!-- END IMAGE PLACE -->
            <div class="fileupload fileupload-new <?php echo ($images->getError('image') ? 'has-error' : ''); ?>" data-provides="fileupload">
                <div>
					<span class="btn default btn-file" style="text-align: left; width: 100%;">
                        <a style="width: 100%; height: 30px" onclick="$('.file-input').last().click();">Chọn ảnh từ máy tính</a>
						<?php
                              $this->widget('CMultiFileUpload', array(
                                 'model'=>$images,
                                 'attribute'=>'images',
                                 'value'=>$images,
                                 'accept'=>'jpg|gif|png',
                                 'selected'=>'',
                                 'remove'=>'<i class="icon-trash"></i>',
                                 'options'=>array(
                                    /*'afterFileAppend'=>'function(e, v, m){
                                        readURL(e);
                                        }',*/
                                     //'onFileRemove'=>'function(e, v, m){ alert("onFileRemove - "+v) }',
                                     //'afterFileRemove'=>'function(e, v, m){ alert("afterFileRemove - "+v) }',
                                 ),
                                 'denied'=>'File is not allowed',
                                 'max'=>10, // max 10 files
                                 'htmlOptions'=>array('class'=>'file-input','style'=>'display: none'),
                                 
                              ));
                            ?>
                            <?php if (!$model->isNewRecord):?>
                                <?php foreach($listImage as $data):?>
                                    <p id="place-image-<?php echo $data->id;?>"><a href="javascript: void(0);" onclick="delPlaceImage(<?php echo $data->id;?>);"><i class="icon-trash"></i></a> <?php echo $data->image;?></p>
                                <?php endforeach;?>
                            <?php endif;?>
					</span>
				</div>
                <?php echo $form->error($images, 'image', array('class'=>'help-block')); ?>
			</div>
            
        </div>
        <div class="col-md-9">
            <div class="form-group <?php echo ($model->getError('title') ? 'has-error' : ''); ?>">
                <?php echo $form->labelEx($model, 'title', array('class'=>'control-label')); ?>
                <?php echo $form->textField($model, 'title', array('class'=>'form-control')); ?>
                <?php echo $form->error($model, 'title', array('class'=>'help-block')); ?>
            </div>
            
            <div class="form-group <?php echo ($model->getError('brief') ? 'has-error' : ''); ?>">
                <?php echo $form->labelEx($model, 'brief', array('class'=>'control-label')); ?>
                <?php echo $form->textArea($model, 'brief', array('class'=>'form-control', 'rows'=>5)); ?>
                <?php echo $form->error($model, 'brief', array('class'=>'help-block')); ?>
            </div>
            
            <div class="form-group <?php echo ($model->getError('status') ? 'has-error' : ''); ?>">
                <?php echo $form->labelEx($model, 'status', array('class'=>'control-label')); ?>
                <?php echo $form->dropDownList($model, 'status', array('A'=>'Hoạt động', 'I'=>'Ngừng hoạt động', 'P'=>'Chờ duyệt'), array('class'=>'form-control')); ?>
                <?php echo $form->error($model, 'status', array('class'=>'help-block')); ?>
            </div>
            
            <div class="form-group <?php echo ($model->getError('website') ? 'has-error' : ''); ?>">
                <?php echo $form->labelEx($model, 'website', array('class'=>'control-label')); ?>
                <?php echo $form->textField($model, 'website', array('class'=>'form-control')); ?>
                <?php echo $form->error($model, 'website', array('class'=>'help-block')); ?>
            </div>
            
            <div class="form-group <?php echo ($model->getError('email') ? 'has-error' : ''); ?>">
                <?php echo $form->labelEx($model, 'email', array('class'=>'control-label')); ?>
                <?php echo $form->textField($model, 'email', array('class'=>'form-control')); ?>
                <?php echo $form->error($model, 'email', array('class'=>'help-block')); ?>
            </div>
            
            <div class="form-group <?php echo ($model->getError('url') ? 'has-error' : ''); ?>">
                <?php echo $form->labelEx($model, 'url', array('class'=>'control-label')); ?>
                <?php echo $form->textField($model, 'url', array('class'=>'form-control')); ?>
                <?php echo $form->error($model, 'url', array('class'=>'help-block')); ?>
            </div>
        </div>
    </div>
</div>

<!-- Place Location  -->
<div class="form-body">
    <div class="row">
        <!-- IMAGE MAP -->
        <div class="col-md-3">
            <div class="fileupload fileupload-new <?php echo ($location->getError('title') ? 'has-error' : ''); ?>" data-provides="fileupload">
				<div class="fileupload-new thumbnail" style="width: 240px; height: 150px;">
                <?php if ($location->isNewRecord) : ?>
					<img src="<?php echo Yii::app()->theme->baseUrl; ?>/img/no_image.gif" alt="" />
                <?php else : ?>
                	<img src="<?php echo $this->getImageUrl() . 'places/' . date('Ymd', strtotime($model->createddate)) . '/' . $location->map; ?>" alt="" />
                <?php endif; ?>
				</div>
				<div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 240px; max-height: 150px; line-height: 20px;"></div>
				<div>
					<span class="btn default btn-file">
						<span class="fileupload-new"><i class="icon-paper-clip"></i> Select image</span>
						<span class="fileupload-exists"><i class="icon-undo"></i> Change</span>
						<?php echo $form->fileField($location, 'map', array('class'=>'default')); ?>
					</span>
					<a href="#" class="btn red fileupload-exists" data-dismiss="fileupload"><i class="icon-trash"></i> Remove</a>
				</div>
                <?php echo $form->error($location, 'map', array('class'=>'help-block')); ?>
			</div>
        </div>
        <!-- END IMAGE MAP -->
        
        <div class="col-md-9">
            <!-- ADDRESS -->
            <div class="row">
               <div class="col-md-5">
                    <div class="form-group <?php echo ($location->getError('address') ? 'has-error' : ''); ?>">
                        <?php echo $form->labelEx($location, 'address', array('class'=>'control-label')); ?>
                        <?php echo $form->textField($location, 'address', array('class'=>'form-control')); ?>
                        <?php echo $form->error($location, 'address', array('class'=>'help-block')); ?>
                    </div>
               </div>
               <div class="col-md-1"></div>
               <div class="col-md-6">
                     <div class="form-group <?php echo ($location->getError('ward') ? 'has-error' : ''); ?>">
                        <?php echo $form->labelEx($location, 'ward', array('class'=>'control-label ')); ?>
                        <?php echo $form->textField($location, 'ward', array('class'=>'form-control',)); ?>
                        <?php echo $form->error($location, 'ward', array('class'=>'help-block')); ?>
                    </div>
               </div>
            </div>
            <!-- END ADDRESS -->
            <!-- DISTRICT -->
            <div class="row">
               <div class="col-md-5">
                    <div class="form-group <?php echo ($location->getError('district_id') ? 'has-error' : ''); ?>">
                        <?php echo $form->labelEx($location, 'district_id', array('class'=>'control-label ')); ?>
                        <?php echo $form->dropDownList($location, 'district_id', $location->getDistrict(), array('class'=>'form-control', 'prompt'=>"Chọn khu vực")); ?>
                        <?php echo $form->error($location, 'district_id', array('class'=>'help-block')); ?>
                    </div>
               </div>
               <div class="col-md-1">OR</div>
               <div class="col-md-6">
                     <div class="form-group <?php echo ($location->getError('district') ? 'has-error' : ''); ?>">
                        <?php echo $form->labelEx($location, 'district', array('class'=>'control-label ')); ?>
                        <?php echo $form->textField($location, 'district', array('class'=>'form-control',)); ?>
                        <?php echo $form->error($location, 'district', array('class'=>'help-block')); ?>
                    </div>
               </div>
            </div>
            <!-- END DISTRICT -->
            
            <!-- CITY -->
            <div class="row">
               <div class="col-md-5">
                    <div class="form-group <?php echo ($location->getError('city_id') ? 'has-error' : ''); ?>">
                        <?php echo $form->labelEx($location, 'city_id', array('class'=>'control-label ')); ?>
                        <?php echo $form->dropDownList($location, 'city_id', $location->getCity(), array('class'=>'form-control', 'prompt'=>'Chọn thành phố')); ?>
                        <?php echo $form->error($location, 'city_id', array('class'=>'help-block')); ?>
                    </div>
               </div>
               <div class="col-md-1">OR</div>
               <div class="col-md-6">
                     <div class="form-group <?php echo ($location->getError('city') ? 'has-error' : ''); ?>">
                        <?php echo $form->labelEx($location, 'city', array('class'=>'control-label ')); ?>
                        <?php echo $form->textField($location, 'city', array('class'=>'form-control',)); ?>
                        <?php echo $form->error($location, 'city', array('class'=>'help-block')); ?>
                    </div>
               </div>
            </div>
            <!-- END CITY -->
            
            <!-- COUNTRY -->
            <div class="row">
               <div class="col-md-5">
                    <div class="form-group <?php echo ($location->getError('country_id') ? 'has-error' : ''); ?>">
                        <?php echo $form->labelEx($location, 'country_id', array('class'=>'control-label ')); ?>
                        <?php echo $form->dropDownList($location, 'country_id', $location->getCountries(), array('class'=>'form-control', 'prompt'=>'Chọn quốc gia')); ?>
                        <?php echo $form->error($location, 'country_id', array('class'=>'help-block')); ?>
                    </div>
               </div>
               <div class="col-md-1">OR</div>
               <div class="col-md-6">
                     <div class="form-group <?php echo ($location->getError('country') ? 'has-error' : ''); ?>">
                        <?php echo $form->labelEx($location, 'country', array('class'=>'control-label ')); ?>
                        <?php echo $form->textField($location, 'country', array('class'=>'form-control',)); ?>
                        <?php echo $form->error($location, 'country', array('class'=>'help-block')); ?>
                    </div>
               </div>
            </div>
            <!-- END COUNTRY -->
            
            <div class="row">
                <!-- PHONE -->
               <div class="col-md-5">
                    <div class="form-group <?php echo ($location->getError('phone') ? 'has-error' : ''); ?>">
                        <?php echo $form->labelEx($location, 'phone', array('class'=>'control-label ')); ?>
                        <?php echo $form->textField($location, 'phone', array('class'=>'form-control',)); ?>
                        <?php echo $form->error($location, 'phone', array('class'=>'help-block')); ?>
                    </div>
               </div>
               <!-- END PHONE -->
               <div class="col-md-1">AND</div>
               <!-- ALTPHONE -->
               <div class="col-md-6">
                     <div class="form-group <?php echo ($location->getError('altphone') ? 'has-error' : ''); ?>">
                        <?php echo $form->labelEx($location, 'altphone', array('class'=>'control-label ')); ?>
                        <?php echo $form->textField($location, 'altphone', array('class'=>'form-control',)); ?>
                        <?php echo $form->error($location, 'altphone', array('class'=>'help-block')); ?>
                    </div>
               </div>
               <!-- END ALTPHONE -->
            </div>
            <!-- FAX-->
            <div class="form-group <?php echo ($location->getError('fax') ? 'has-error' : ''); ?>">
                <?php echo $form->labelEx($location, 'fax', array('class'=>'control-label')); ?>
                <?php echo $form->textField($location, 'fax', array('class'=>'form-control')); ?>
                <?php echo $form->error($location, 'fax', array('class'=>'help-block')); ?>
            </div>
            <!-- END FAX -->
        </div>
    </div>
</div>
<!-- END PLACE LOCATION -->

<!-- PLACE PROFILE -->
<div class="form-body">
    <div class="row">
        <div class="col-md-3">
        </div>
        <div class="col-md-9">
            <div class="form-group <?php echo ($profile->getError('description') ? 'has-error' : ''); ?>">
                <?php echo $form->labelEx($profile, 'description', array('class'=>'control-label')); ?>
                <?php echo $form->textArea($profile, 'description', array('class'=>'form-control', 'rows'=>5)); ?>
                <?php echo $form->error($profile, 'description', array('class'=>'help-block')); ?>
            </div>
        </div>
    </div>
</div>
<!-- END PLACE PROFILE-->

<!-- PLACE SOCIAL -->
<div class="form-body">
    <div class="row">
        <div class="col-md-3">
        </div>
        <div class="col-md-9">
            <div id="listSocial">
                <?php if ($model->isNewRecord):?>
                    <div class="row">
                        <div class="col-md-5">
                            <div class="form-group <?php echo ($social->getError('social_id') ? 'has-error' : ''); ?>">
                                <?php echo CHtml::activelabelEx($social, 'social_id', array('class'=>'control-label')); ?>
                                <?php echo CHtml::dropDownList('PlaceSocial[social_id][]', '',$social->getSocial(), array('class'=>'form-control', 'prompt'=>'Chọn Social')); ?>
                                <?php echo CHtml::error($social, 'social_id', array('class'=>'help-block')); ?>
                            </div>
                        </div>
                        <div class="col-md-1">AND</div>
                        <div class="col-md-6">
                            <div class="form-group <?php echo ($social->getError('url') ? 'has-error' : ''); ?>">
                                <?php echo CHtml::activelabelEx($social, 'url', array('class'=>'control-label')); ?>
                                <?php echo CHtml::textField('PlaceSocial[url][]', '', array('class'=>'form-control',)); ?>
                                <?php echo CHtml::error($social, 'url', array('class'=>'help-block')); ?>
                            </div>
                        </div>
                    </div>
                <?php else:?>
                    <?php foreach($social as $data):?>
                        <div class="row">
                            <div class="col-md-5">
                                <div class="form-group <?php echo ($data->getError('social_id') ? 'has-error' : ''); ?>">
                                    <?php echo CHtml::activelabelEx($data, 'social_id', array('class'=>'control-label')); ?>
                                    <?php echo CHtml::dropDownList('PlaceSocial[social_id][]', $data->social_id,$data->getSocial(), array('class'=>'form-control', 'prompt'=>'Chọn Social')); ?>
                                    <?php echo CHtml::error($data, 'social_id', array('class'=>'help-block')); ?>
                                </div>
                            </div>
                            <div class="col-md-1">AND</div>
                            <div class="col-md-6">
                                <div class="form-group <?php echo ($data->getError('url') ? 'has-error' : ''); ?>">
                                    <?php echo CHtml::activelabelEx($data, 'url', array('class'=>'control-label')); ?>
                                    <?php echo CHtml::textField('PlaceSocial[url][]', $data->url, array('class'=>'form-control',)); ?>
                                    <?php echo CHtml::error($data, 'url', array('class'=>'help-block')); ?>
                                </div>
                            </div>
                        </div>
                    <?php endforeach;?>
                <?php endif;?>
            </div>
			<a href="javascript: void(0);" class="btn green pull-right" onclick="addSocial();"><i class="icon-plus"> </i> Thêm Social</a>
        </div>
    </div>
</div>
<!-- END PLACE SOCIAL -->
<div class="form-actions right">
	<button type="reset" class="btn default">Cancel</button>
	<button type="submit" class="btn blue" onClick="Custom.showLoading();"><i class="icon-ok"></i> <?php echo $model->isNewRecord ? 'Đăng tin' : 'Cập nhật tin'; ?></button>
</div>
<?php $this->endWidget(); ?>
<!-- END NEWS FORM -->